package com.yidu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.dao.support.DaoSupport;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.dao.LockerAreaMapper;
import com.yidu.model.LockerArea;
import com.yidu.service.AreaService;
import com.yidu.util.Pages;

/**
 *  服务实现类
 * @author ly
 * @since 2018-10-20
 */
@Service
public class AreaServiceImpl implements AreaService {
	@Resource
	private LockerAreaMapper Mapper;
	
	/**
	 * 查询
	 */
	@Override
	public List<LockerArea> findAll(LockerArea area,Pages pages) {
		System.out.println("在service里面:"+area.getAreaName());
		Map<String, Object> map =new HashMap<>();
		map.put("area", area);
		map.put("pages", pages);
		return Mapper.selectAll(map);
	}
	
	/**
	 * 增加或者修改
	 */
	@Override
	public int addOrUpdate(LockerArea area) {
		if(area.getAreaId()!=null && !"".equals(area.getAreaId())) {
			return Mapper.updateByPrimaryKeySelective(area);
		}else {
			String uuid=UUID.randomUUID().toString().replaceAll("-", "");
			area.setAreaId(uuid);
			return Mapper.insertSelective(area);
		}
	}
	/**
	 * 修改的上屏
	 */
	@Override
	public LockerArea findById(String areaId) {
		LockerArea lockerarea=Mapper.selectByPrimaryKey(areaId);
		return lockerarea;
	}
	/**
	 * 删除
	 */
	@Override
	public int delete(String areaId) {
		return Mapper.deleteByPrimaryKey(areaId);
	}
	
	/**
	 * 分页
	 */
	@Override
	public int findCount2(LockerArea area) {
		int rows=Mapper.findCount2(area);
		return rows;
	}
	
	@Override
	public List<LockerArea> selectboxAll() {
		return Mapper.selectboxAll();
	}
}
